﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace NguyenQuangKhanh_785255
{
    class Connect
    {
        SqlConnection conn;
        public SqlConnection getConnect()
        {
            string conString = @"Data Source=quangkhanh-PC;Initial Catalog=QLBH;Integrated Security=True";
            return new SqlConnection(conString);
        }

       
        // Phương thức trả về bảng select
        public DataTable getTable(String sql)
        {
            DataTable dt = new DataTable();
            try
            {

                SqlConnection conn = getConnect();
                SqlDataAdapter ad = new SqlDataAdapter(sql, conn);
                ad.Fill(dt);

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return dt;
        }
        public void ExcuteQuerySql(string sql)
        {
            try
            {
                SqlConnection conn = getConnect();
                conn.Open();
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.ExecuteNonQuery();
                cmd.Dispose();
                conn.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

        }
    }
}
